<template>
	<div>
		<h1 style="font-size: 30px;margin-bottom:10px">草稿箱</h1>
		<el-table :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)" v-loading="loading">
			<el-table-column prop="userName" label="创建人" width="100px"></el-table-column>
			<el-table-column prop="title" label="标题"></el-table-column>
			<el-table-column prop="modifyDate" label="修改日期"></el-table-column>
			<el-table-column prop="readCount" label="阅读次数"></el-table-column>
			<el-table-column fixed="right" label="操作">
				<template slot-scope="scope">
					<el-button @click="preview(scope.row)" type="text" >查看</el-button>
					<el-button @click="edit(scope.row)" type="text">编辑</el-button>
					<el-button @click="publish(scope.row)" type="text" >发布</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination layout="total,sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" 
		:current-page="currentPage" :page-size="pageSize" @current-change="handleCurrentChange" :page-sizes="[ 4, 8, 12]">
		</el-pagination>
	</div>
</template>

<script>
export default {
  name: "Draft",
  data() {
    return {
      tableData: [],
      isDraft: 1,
      loading: true,
      currentPage: 1, //当前页数
      pageSize: 4, //当前页记录数
      total: 0, //总条数
    };
  },
  methods: {
    loadBlogList() {
      this.axios.get("/blog/blogList/" + this.isDraft).then((res) => {
        this.tableData = res.data.blogList;
        this.loading = false;
		this.total = this.tableData.length;
      });
    },
    preview(row) {
      this.$router.push("./Blog/BlogDetail/" + row.blogId);
    },
    edit(row) {
      this.$router.push("./Blog/edit/" + row.blogId);
    },
    publish(row) {
      this.axios.get(`/blog/publish/${row.blogId}`).then((res) => {
        if (res.data.success) {
          if (res.data.success) {
            this.$message.success(res.data.msg);
            this.$router.push("./blog/BlogList");
          } else {
            this.$message.error(res.data.msg);
          }
        }
      });
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
  },
  mounted() {
    this.loadBlogList();
  },
};
</script>

<style>
</style>
